package com.new2i.action;
 
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.new2i.service.able.UserService;
import com.weixin.util.WeixinHttpUtil; 

/**
 * 用户视图控制器－视图
 * 
 * @since 2015/09/01
 * @author 2i
 *
 */
@Controller
@RequestMapping("page/user")
public class UserPageAction extends BaseAction {
	
	@Autowired
	private transient UserService mUserService;
	
	private static Logger logger = Logger.getLogger(UserPageAction.class);
	
	/**
	 * 用户常用就诊人
	 * 
	 * @author 2i
	 * @since 2015/09/01
	 * @param request
	 * @param response
	 * @param code
	 * @return
	 */
	@RequestMapping("/contact/list")
	public ModelAndView contactListPage(HttpServletRequest request,HttpServletResponse response,String code) {
		ModelAndView mav = new ModelAndView(); 
		logger.debug("code"+code);  
		String wxid = null;
		Object oWxid = request.getSession().getAttribute("wxid");
		if (oWxid == null || oWxid.toString().length() < 0) {
			//session中无 wxid从微信请求
			wxid = WeixinHttpUtil.getInstance().getWxidByOauth2Code(code); 
			request.getSession().setAttribute("wxid", wxid);
		}else {
			wxid = oWxid.toString();
		}  
		List<HashMap<String,Object>> contactList = mUserService.selectContactListByWxid(wxid); 
		logger.debug("contactList length"+contactList.size());
		mav.setViewName("/views/contact_list.jsp");
		mav.addObject("contact_list",contactList);
		return mav;
	}

}
